﻿@using EquipmentManager.Entities
@model EquipmentManager.Models.ListModel<PostOffice, Region>

@{
    ViewBag.Title = "Список отделений в " + Model.Parent.Name + " в дирекции " + Model.Parent.Directorate.Name;
}

@section menu {
    <section class="featured">
            <div class="master-menu">
                @{Html.RenderPartial("AdminMenu");}
            </div>
    </section>
}

<p>@Html.ActionLink("+ Добавить новое отделение", "CreatePostOffice", "Admin", new { @RegionId = Model.Parent.Id}, new { @class = "common-btn BlueColor" }) @Html.ActionLink("+ Добавить нового пользователя", "CreateUser", "Admin", new { @RegionId = Model.Parent.Id}, new { @class = "common-btn BlueColor" })</p>

<h2>Список отделений @Model.Parent.Name в дирекции @Model.Parent.Directorate.Name</h2>

<table class="bordered">
    <thead>
        <tr>
            <th>Оборудование</th>
            <th>Добавить</th>
            <th>Название</th>
            <th>Оборудований</th>
            <th>Правка</th>
            <th>Удалить</th>
        </tr>
    </thead>
    @foreach (var postOffice in Model.ListItems)
    {
        <tr>
            <td class="Center column-detail">@Html.ActionLink("Оборудование", "Equipments", "Admin", new { PostOfficeId = postOffice.Id }, new { @class = "common-btn BlueColor" })</td>
            <td class="Center column-detail">@Html.ActionLink("+ Обору-ние", "CreateEquipment", "Admin", new { PostOfficeId = postOffice.Id }, new { @class = "common-btn BlueColor" })</td>
            <td>@postOffice.Name</td>
            <td class="Center">@postOffice.Equipments.Where(e => e.Status == EntityStatus.Active).Count()</td>
            <td class="Center column-detail">@Html.ActionLink("Правка", "EditPostOffice", "Admin", new { PostOfficeId = postOffice.Id }, new { @class = "common-btn BlueColor" })</td>
            <td class="Center column-detail">@Html.ActionLink("Удалить", "DeletePostOffice", "Admin", new { PostOfficeId = postOffice.Id }, new { @class = "common-btn RedColor" })</td>
        </tr>
    }
</table>

<h2>Список пользователей @Model.Parent.Name в дирекции @Model.Parent.Directorate.Name</h2>

<table class="bordered">
    <thead>
        <tr>
            <th>Логин</th>
            <th>ФИО</th>
            <th>Дата регистрации</th>
            <th>Район</th>
            <th>Дирекция</th>
            <th>Правка</th>
            <th>Удалить</th>
        </tr>
    </thead>
    @foreach (var user in Model.Parent.Users)
    {
        if(user.Status != EntityStatus.Deleted)
        {
            <tr>
                <td>@user.UserName</td>
                <td>@user.FullName</td>
                <td>@user.RegistredDate</td>
                <td>@user.Region.Name</td>
                <td>@user.Region.Directorate.Name</td>
                <td class="Center column-detail">@Html.ActionLink("Правка", "EditUser", "Admin", new { UserId = user.Id }, new { @class = "common-btn BlueColor" })</td>
                <td class="Center column-detail">@Html.ActionLink("Удалить", "DeleteUser", "Admin", new { UserId = user.Id }, new { @class = "common-btn RedColor" })</td>
            </tr>
        }
    }
</table>

<p>
     @Html.ActionLink("Назад", "Regions", "Admin", new { @DirectorateId = Model.Parent.Directorate.Id }, new { @class = "common-btn-large BlueColor" })
</p>
